package system

//QueryUserMenus 获取用户菜单信息
const queryMenusByIdent = `
select 
s.id,
s.name,
s.parent,
s.level_id,
s.icon,
s.path,
s.enable,
s.is_open
from sso_system_menu s
inner join sso_system_info sys on sys.id = s.sys_id
where &sys.ident
order by s.parent asc,s.level_id desc,s.sortrank asc`

//queryRoleMenus 获取用户菜单信息
const queryMenusBySysID = `
select 
s.id,
s.name,
s.parent,
s.level_id,
s.icon,
s.path,
s.enable,
s.is_open
from sso_system_menu s
inner join sso_system_info sys on sys.id = s.sys_id
where &sys.id
order by s.parent asc,s.level_id desc,s.sortrank asc`

const queryMenuByRoleID = `
select 
s.id,
s.name,
s.parent,
s.level_id,
s.icon,
s.path,
s.enable,
s.is_open
from sso_system_menu s
inner join sso_system_info sys on sys.id = s.sys_id
inner join sso_role_menu sm on sm.menu_id=s.id and sm.sys_id=sys.id and sm.role_id=@role_id
where sys.id=@id
order by s.parent asc,s.level_id desc,s.sortrank asc`

const deleteRoleMenuByRole = `
delete 
from sso_role_menu  
where role_id=@role_id
and sys_id=@sys_id`

const insertRoleMenuByRole = `
insert into sso_role_menu(
	sys_id,
	role_id,
	menu_id,
	enable,
	sortrank)
select 
	t.sys_id,
	@role_id,
	t.id,
	0,
	t.sortrank 
from sso_system_menu t 
where t.id=@id and t.sys_id=@sys_id`

const updateSystemSecret = `
update sso_system_info t 
set t.secret=@secret
where t.id=@id`
